package com.zjb.zjbHome.beans.model;

import java.util.List;

import com.zjb.zjbHome.beans.base.BaseUrl;

public class Url extends BaseUrl<Url> {

	private static final long serialVersionUID = -1464362619619500540L;
	
	public static final Url dao = new Url();
	
	public List<Url> search(){
		return this.find("select * from url");
	}

	public int add(String urlName, String urlPath, String introduce) {
		Url urls = new Url();
		urls.setUrlName(urlName);
		urls.setUrl(urlPath);
		urls.setIntroduce(introduce);
		urls.save();
		
		return urls.getId();
	}

	public List<Url> loadData() {
		return this.find("select * from url");
	}

	public List<Url> search(String websiteKey) {
		// TODO Auto-generated method stub
		return this.find(
					"select * " +
					"from " +
					"	url " +
					"where " +
					"	( ? is null or `url` like concat('%', ?, '%') or `urlName` like concat('%', ?, '%') or `introduce` like concat('%', ?, '%') )",
					websiteKey, websiteKey, websiteKey, websiteKey);
	}

	public List<Url> search(String websiteKey, Integer classifyId) {
		// TODO Auto-generated method stub
		return this.find(
				"select * " +
				"from " +
				"	url " +
				"where " +
				"	( ? is null or `classifyId` = ? ) and" +
				"	( ? is null or `url` like concat('%', ?, '%') or `urlName` like concat('%', ?, '%') or `introduce` like concat('%', ?, '%') )",
				classifyId, classifyId,
				websiteKey, websiteKey, websiteKey, websiteKey);
	}

	public Boolean addWebsite(String urlName, String url, String introduce, Integer classifyId) {
		// TODO Auto-generated method stub
		Url urls = new Url();
		urls.setUrlName(urlName);
		urls.setUrl(url);
		urls.setIntroduce(introduce);
		urls.setClassifyId(classifyId);
		urls.save();
		
		return true;
	}

	public Boolean editWebsite(Integer id, String urlName, String url, String introduce, Integer classifyId) {
		Url urls = this.findById(id);
		urls.setUrlName(urlName);
		urls.setUrl(url);
		urls.setIntroduce(introduce);
		urls.setClassifyId(classifyId);
		urls.update();
		return true;
	}

}
